<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Return a string describing a socket error</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.socket-shutdown.html">socket_shutdown</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.socket-write.html">socket_write</a></div>
 <div class="up"><a href="ref.sockets.html">Socket 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.socket-strerror" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">socket_strerror</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5)</p><p class="refpurpose"><span class="refname">socket_strerror</span> &mdash; <span class="dc-title">Return a string describing a socket error</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.socket-strerror-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>socket_strerror</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$errno</code></span>
   )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>socket_strerror()</strong></span> takes as its
   <em><code class="parameter">errno</code></em> parameter a socket error code as returned by
   <span class="function"><a href="function.socket-last-error.html" class="function">socket_last_error()</a></span> and returns the corresponding
   explanatory text.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Although the error messages generated by the socket extension are in 
    English, the system messages retrieved with this function will appear
    depending on the current locale (<strong><code>LC_MESSAGES</code></strong>).
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.socket-strerror-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">errno</code></em></dt>

     <dd>

      <p class="para">
       A valid socket error number, likely produced by 
       <span class="function"><a href="function.socket-last-error.html" class="function">socket_last_error()</a></span>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.socket-strerror-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the error message associated with the <em><code class="parameter">errno</code></em>
   parameter.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.socket-strerror-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4506">
    <p><strong>Example #1 <span class="function"><strong>socket_strerror()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">==&nbsp;(</span><span style="color: #0000BB">$socket&nbsp;</span><span style="color: #007700">=&nbsp;@</span><span style="color: #0000BB">socket_create</span><span style="color: #007700">(</span><span style="color: #0000BB">AF_INET</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SOCK_STREAM</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SOL_TCP</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"socket_create()&nbsp;failed:&nbsp;reason:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">socket_strerror</span><span style="color: #007700">(</span><span style="color: #0000BB">socket_last_error</span><span style="color: #007700">())&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br />if&nbsp;(</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">==&nbsp;(@</span><span style="color: #0000BB">socket_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$socket</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'127.0.0.1'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">80</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"socket_bind()&nbsp;failed:&nbsp;reason:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">socket_strerror</span><span style="color: #007700">(</span><span style="color: #0000BB">socket_last_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$socket</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     The expected output from the above example (assuming the script
     is not run with root privileges):
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
socket_bind() failed: reason: Permission denied
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.socket-strerror-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.socket-accept.html" class="function" rel="rdfs-seeAlso">socket_accept()</a> - Accepts a connection on a socket</span></li>
    <li class="member"><span class="function"><a href="function.socket-bind.html" class="function" rel="rdfs-seeAlso">socket_bind()</a> - Binds a name to a socket</span></li>
    <li class="member"><span class="function"><a href="function.socket-connect.html" class="function" rel="rdfs-seeAlso">socket_connect()</a> - Initiates a connection on a socket</span></li>
    <li class="member"><span class="function"><a href="function.socket-listen.html" class="function" rel="rdfs-seeAlso">socket_listen()</a> - Listens for a connection on a socket</span></li>
    <li class="member"><span class="function"><a href="function.socket-create.html" class="function" rel="rdfs-seeAlso">socket_create()</a> - 创建一个套接字（通讯节点）</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.socket-shutdown.html">socket_shutdown</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.socket-write.html">socket_write</a></div>
 <div class="up"><a href="ref.sockets.html">Socket 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
